package com.dz.scrm.app.adpter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.dz.scrm.R;
import com.dz.scrm.mvp.model.entity.LoginCompanyBean;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

/**
 * @Description: 类作用描述
 * @Author: 黄海
 * @CreateDate: 2021-4-23 9:56
 * @UpdateUser: 黄海
 * @UpdateDate: 2021-4-23 9:56
 * @UpdateRemark: 更新说明
 */
public class companyAdpter extends RecyclerView.Adapter<companyAdpter.ViewHolder>{

    private Context context;
    private List<LoginCompanyBean> data;
    private itemOnClickListener listener;
    public companyAdpter(Context context,List<LoginCompanyBean> data,itemOnClickListener listener) {
        this.context = context;
        this.data = data;
        this.listener = listener;
    }

    @NonNull
    @Override
    public companyAdpter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_company_recycle_layout,parent,false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        if (data != null && data.get(position) != null){
            holder.name.setText(data.get(position).getName());
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (listener != null){
                        listener.onClick(position);
                    }
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{

        private TextView name;
        private RelativeLayout itemLayout;

        public ViewHolder(View itemView) {
            super(itemView);
            name = itemView.findViewById(R.id.tvTitle);
            itemLayout = itemView.findViewById(R.id.itemLayout);
        }
    }

    public interface itemOnClickListener{
        void onClick(int position);
    }
}
